import 'package:flutter/material.dart';
import 'package:proj_shop/constant/constant.dart';
import 'package:proj_shop/http/weibo/http_weibo.dart';
import 'package:proj_shop/http/weibo/weibo_service_url.dart';
import 'package:proj_shop/roots/weibo/model/VedioCategory.dart';
import 'package:proj_shop/roots/weibo/model/VedioCategoryList.dart';
import 'package:proj_shop/roots/weibo/pages/video/weibo_video_hot_page.dart';
import 'package:proj_shop/roots/weibo/pages/video/weibo_video_recommend_page.dart';
import 'package:proj_shop/roots/weibo/pages/video/weibo_video_small_video_page.dart';

class WeiboVideoPage extends StatefulWidget {
  @override
  _WeiboVideoPageState createState() => _WeiboVideoPageState();
}

class _WeiboVideoPageState extends State<WeiboVideoPage>
    with TickerProviderStateMixin {
  TabController mTabController;
  List<VedioCategory> mTabList = new List();

  @override
  void initState() {
    mTabList.add(new VedioCategory(id: 1, cname: "推荐"));
    mTabList.add(new VedioCategory(id: 2, cname: "热门"));
    mTabList.add(new VedioCategory(id: 3, cname: "小视频"));
    mTabController = TabController(length: mTabList.length, vsync: this);

    HttpWeibo().post(
      WeiboServiceUrl.getVedioCategory,
      null,
      (data) {
        List<VedioCategory> mList =
            VedioCategoryList.fromJson(data['data']).data;
        setState(() {
          mTabList = mList;
          mTabController = TabController(length: mTabList.length, vsync: this);
        });
      },
      (error) {},
    );

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Column(
          children: [
            Container(
              alignment: Alignment.center,
              height: 50,
              child: TabBar(
                tabs: mTabList.map((value) {
                  return Text(value.cname);
                }).toList(),
                isScrollable: true,
                indicatorColor: Colors.transparent,
                labelColor: Color(0xffF78005),
                unselectedLabelColor: Color(0xff666666),
                labelStyle: TextStyle(
                  fontSize: 17.0,
                  fontWeight: FontWeight.w700,
                ),
                unselectedLabelStyle: TextStyle(fontSize: 16.0),
                indicatorSize: TabBarIndicatorSize.label,
                controller: mTabController,
              ),
            ),
            Container(
              child: Center(
                child: Container(
                  width: MediaQuery.of(context).size.width,
                  margin: EdgeInsets.only(left: 10, right: 10),
                  padding: EdgeInsets.only(top: 8, bottom: 8),
                  decoration: BoxDecoration(
                    color: Color(0xffE4E2E8),
                    borderRadius: BorderRadius.all(
                      //圆角
                      Radius.circular(5.0),
                    ),
                  ),
                  child: Center(
                    child: Container(
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          Container(
                            margin: EdgeInsets.only(right: 5, top: 2),
                            child: Image.asset(
                              Constant.ASSETS_IMG + 'find_top_search.png',
                              width: 12.0,
                              height: 15.0,
                            ),
                          ),
                          Text(
                            "搜你想看的视频",
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(
                                fontSize: 14, color: Color(0xffee565656)),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            ),
            Expanded(
              flex: 1,
              child: TabBarView(
                children: <Widget>[
                  WeiboVideoRecommendPage(),
                  WeiboVideoHotPage(),
                  WeiboVideoSmallVideoPage(),
                ],
                controller: mTabController,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
